package com.demo.thread.demo_thread_create_way;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @author peter
 * @date 2022/3/16 01:23
 */
public class Demo3_hutool_callable implements Callable<String> {

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"-当前剩余票数:"+i);
        }
        return "Sale out";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Demo3_hutool_callable callable = new Demo3_hutool_callable();

        // 和demo3不同, callable 直接 执行
        Future<String> stringFuture1 = ThreadUtil.execAsync(callable);
        Future<String> stringFuture2 = ThreadUtil.execAsync(callable);
        System.out.println(stringFuture1.get());
        System.out.println(stringFuture2.get());
    }
}
